<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 文本框 -->
      <p>Message is: {{ message }}</p>
      <input v-model="message" placeholder="edit me" />

      <hr />

      <!-- 多行文本框 -->
      <span>Multiline message is:</span>
      <p style="white-space: pre-line">{{ message2 }}</p>
      <textarea v-model="message2" placeholder="add multiple lines"></textarea>

      <hr />

      <!-- 复选框 -->
      <!-- 单个复选框的时候，v-model会帮我们去绑定布尔值 -->
      <input type="checkbox" id="checkbox" v-model="checked" />
      <label for="checkbox">{{ checked }}</label>

      <!-- 当同时有多个复选框绑定同一个变量的时候，这个变量会变成数组 -->
      <div>Checked names: {{ checkedNames }}</div>
      <input type="checkbox" id="jack" value="Jack" v-model="checkedNames" />
      <label for="jack">Jack</label>
      <input type="checkbox" id="john" value="John" v-model="checkedNames" />
      <label for="john">John</label>
      <input type="checkbox" id="mike" value="Mike" v-model="checkedNames" />
      <label for="mike">Mike</label>

      <hr />

      <!-- 单选按钮 -->
      <!-- 对于单选按钮来说绑定的是字符串 -->
      <div>Picked: {{ picked }}</div>
      <input type="radio" id="one" value="One" v-model="picked" />
      <label for="one">One</label>
      <input type="radio" id="two" value="Two" v-model="picked" />
      <label for="two">Two</label>

      <hr />

      <!-- 下拉菜单 -->
      <!-- 绑定的也是字符串 -->
      <div>Selected: {{ selected }}</div>
      <select v-model="selected">
        <option disabled value="">Please select one</option>
        <option value="a">A</option>
        <option value="b">B</option>
        <option value="c">C</option>
      </select>

      <hr />

      <!-- 多选的下拉菜单 -->
      <!-- 绑定的是数组 -->
      <div>Selected2: {{ selected2 }}</div>
      <select v-model="selected2" multiple>
        <option>A</option>
        <option>B</option>
        <option>C</option>
      </select>

      <hr />

      <!-- 改变单个复选框的绑定值 -->
      <input
        type="checkbox"
        v-model="toggle"
        true-value="yes"
        false-value="no"
      />
      <span>{{ toggle }}</span>
    </div>

    <script src="./Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            message: "",
            message2: "",
            checked: true,
            checkedNames: ["John"],
            picked: "",
            selected: "",
            selected2: [],
            toggle: "yes",
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
